package cn.wolf.lbs;

import android.content.Context;
import android.location.LocationManager;

/**
 * <h3>GPS定位        </h3>
 * <p>GPS定位，包括：</p>
 * <p>1.仅启动GPS定位</p>
 * <p>2.启动GPS定位，当定位到后，回调</p>
 */
public class GPSLocation {

	/**
	 * 开启GPS定位
	 * @param ctx  上下文
	 */
	public static void startLocation(Context ctx) {
		LocationManager locationManager = (LocationManager) ctx
				.getSystemService(Context.LOCATION_SERVICE);
		String provider = LocationManager.GPS_PROVIDER;
		MyLocationListener listener = new MyLocationListener(ctx, locationManager);
		if (locationManager.isProviderEnabled(provider)) {
			locationManager.requestLocationUpdates(provider, 1000L, 0.0f, listener);
		}
	}

	/**
	 * 开启GPS定位，通过回调回去定位数据
	 * @param ctx 上下文
	 * @param iCall 回调接口
	 */
	public static void startLocation(Context ctx, ILbsCallBack iCall) {
		LocationManager locationManager = (LocationManager) ctx
				.getSystemService(Context.LOCATION_SERVICE);
		String provider = LocationManager.GPS_PROVIDER;
		MyLocationListener listener = new MyLocationListener(ctx, locationManager, iCall);
		if (locationManager.isProviderEnabled(provider)) {
			locationManager.requestLocationUpdates(provider, 1000L, 0.0f, listener);
		}
	}

}
